package jobs;

// 抽象产品：手机
abstract class Phone {
    public abstract void call();
}

// 抽象产品：电脑
abstract class Computer {
    public abstract void compute();
}

// 具体产品：安卓手机
class AndroidPhone extends Phone {
    @Override
    public void call() {
        System.out.println("使用安卓手机打电话");
    }
}

// 具体产品：苹果手机
class ApplePhone extends Phone {
    @Override
    public void call() {
        System.out.println("使用苹果手机打电话");
    }
}

// 具体产品：联想电脑
class LenovoComputer extends Computer {
    @Override
    public void compute() {
        System.out.println("使用联想电脑计算");
    }
}

// 具体产品：戴尔电脑
class DellComputer extends Computer {
    @Override
    public void compute() {
        System.out.println("使用戴尔电脑计算");
    }
}

// 抽象工厂
abstract class ElectronicsFactory {
    public abstract Phone createPhone();
    public abstract Computer createComputer();
}

// 具体工厂：安卓+联想
class AndroidLenovoFactory extends ElectronicsFactory {
    @Override
    public Phone createPhone() {
        return new AndroidPhone();
    }
    @Override
    public Computer createComputer() {
        return new LenovoComputer();
    }
}

// 具体工厂：苹果+戴尔
class AppleDellFactory extends ElectronicsFactory {
    @Override
    public Phone createPhone() {
        return new ApplePhone();
    }
    @Override
    public Computer createComputer() {
        return new DellComputer();
    }
}

// 测试类
public class ElectronicsFactoryTest {
    public static void main(String[] args) {
        // 安卓手机+联想电脑工厂
        ElectronicsFactory factory1 = new AndroidLenovoFactory();
        Phone phone1 = factory1.createPhone();
        Computer computer1 = factory1.createComputer();
        phone1.call();
        computer1.compute();

        // 苹果手机+戴尔电脑工厂
        ElectronicsFactory factory2 = new AppleDellFactory();
        Phone phone2 = factory2.createPhone();
        Computer computer2 = factory2.createComputer();
        phone2.call();
        computer2.compute();
    }
}
